package com.ag.zrt.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbLogPlanStep;
import com.ag.common.AgException;
import com.ag.common.BaseAction;
import com.ag.zrt.service.ILogPlanStepService;

@Controller("logPlanStepAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class LogPlanStepAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1922455351647328966L;
	@Resource(name = "LogPlanStepService")
	private ILogPlanStepService logPlanStepService;
	private List<TbLogPlanStep> stepList;
	private TbLogPlanStep logPlanStep;
	private int curStepNum;
	private String eventId;
	private String curStepId; // 当前环节ID
	private String stepName;// 新步骤名称
	private String newStepId;// 返回新步骤ID

	public String getNewStepId() {
		return newStepId;
	}

	public void setNewStepId(String newStepId) {
		this.newStepId = newStepId;
	}

	public String getStepName() {
		return stepName;
	}

	public void setStepName(String stepName) {
		this.stepName = stepName;
	}

	public String getCurStepId() {
		return curStepId;
	}

	public void setCurStepId(String curStepId) {
		this.curStepId = curStepId;
	}

	public String getEventId() {
		return eventId;
	}

	public void setEventId(String eventId) {
		this.eventId = eventId;
	}

	public int getCurStepNum() {
		return curStepNum;
	}

	public TbLogPlanStep getLogPlanStep() {
		return logPlanStep;
	}

	public void setLogPlanStep(TbLogPlanStep logPlanStep) {
		this.logPlanStep = logPlanStep;
	}

	public List<TbLogPlanStep> getStepList() {
		return stepList;
	}

	public void setLogPlanStepService(ILogPlanStepService logPlanStepService) {
		this.logPlanStepService = logPlanStepService;
	}

	public String findAll() {
		try {
			System.out
					.println(eventId
							+ "*************************findAll********eventId****************************");
			stepList = logPlanStepService.findAll(eventId);
			if (stepList.size() > 0) {
				curStepNum = logPlanStepService.getCurStepNum(stepList.get(0)
						.getTbEvent().getEId());

				System.out
						.println(curStepNum
								+ "****************当前序号***curStepNum******************************************************");
			}else{
				System.out.println("***************************当前序号为空**********************************");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "show_succ";
	}

	public String add() {
		System.out
				.println("******************************add new step*************************************************");
		try {
			newStepId = logPlanStepService.save(eventId, curStepId, stepName);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// logPlanStep.setPsId(logPlanStepService.getNewID());

		return "add_succ";
	}

	public String createStartTime() {

		try {
			logPlanStepService.createStartTime(curStepId);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "createStartTime_succ";

	}

	public String createEndTime() {

		try {
			logPlanStepService.createEndTime(curStepId);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "createEndTime_succ";

	}

}
